In [ ]:
%matplotlib inline

import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML

import seaborn

In this little experiment, I printed the likelihoods after each iteration.

The test case was failing with 10% probability and the history had 10 locations. And I requested a certainty for termination of 90%.


In [ ]:
with open('example_run.csv') as f: s = f.read()

In [ ]:
N = 10
runs = [[1/N for _ in range(N)]]
for line in s.split('\n'):
    line = line.strip('[]')
    if len(line) > 0:
        li = [float(i) for i in line.split(',')]
        runs.append(li)

In the next plots you will see that at the beginning the likelihood for the fault location is evenly distributed. There was no observation made.

Then, in the next plot there was an observation ("No fault detected.") at Location 3. Therefore, after Location 3 things are more likely, and on or before it, the fault is less likely.

Scroll down the graphs 'Iteration 14'. Notice that Locations 8 and 9 have dropped to 0, and Location 7 is around 0.25. This means that there was a fault detected at Location 7. Therefore, the algorithm knows that 8 and 9 cannot be the first faulty location.

Afterwards the algorithm evaluates at Location 6 until it is certain that it will not detect the fault there. Once Location 7 reaches certainty/likelihood 90%, the algorithm terminates.


In [ ]:
for i, r in enumerate(runs):
    plt.bar(list(range(10)), r)
    plt.xlabel('Location')
    plt.ylabel('Likelihood after {} iterations'.format(i))
    plt.xticks(range(N))
    plt.show()

In [ ]:
fig, ax = plt.subplots()
# fig.set_tight_layout(True)

ax.set_xlim((0, 10))
ax.set_ylim((0, 1))

line, = ax.plot([], [])

x = list(range(N))

ylabel_func = lambda i: 'Likelihood after {} iterations'.format(i)

def init():
    line.set_data([], [])
    return (line, )

def animate(i):
    y = runs[i]
    line.set_data(x, y)
    return (line,)

anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=72, interval=40, blit=True)

# HTML(anim.to_html5_video())
rc('animation', html='html5')
anim

In [ ]: